package cn.hibernatedemo.dao;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class HibernateUtil {

    private static Configuration configuration;
    private  static SessionFactory sessionfactory;
    //初始化configuration和sessionfactory
    static{
        try {
                configuration=new Configuration().configure();
                sessionfactory=configuration.buildSessionFactory();
            }catch (HibernateException e){
               e.printStackTrace();
            }

    }

    private HibernateUtil(){}
    //获取session对象
    public static Session currentSession(){
        return sessionfactory.getCurrentSession();
    }

}
